<template>
  <div class="app-container">
    <h1 style="color: #303133;">汇总统计</h1>
      <el-row :gutter="40" class="panel-group">
        <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
          <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
            <div class="card-panel-icon-wrapper">
              <svg-icon icon-class="eng" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                总支付
              </div>
              <count-to :start-val="0" :end-val="sumItem.allConsume" :duration="2600" :decimals="2" class="card-panel-num" />
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
          <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
            <div class="card-panel-icon-wrapper">
              <svg-icon icon-class="eng" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                总盈利
              </div>
              <count-to :start-val="0" :end-val="sumItem.allCamExam" :duration="2600" :decimals="2" class="card-panel-num" />
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
          <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
            <div class="card-panel-icon-wrapper">
              <svg-icon icon-class="eng" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                总剩余
              </div>
              <count-to :start-val="0" :end-val="sumItem.allSeExam" :duration="2600" :decimals="2" class="card-panel-num" />
            </div>
          </div>
        </el-col>
      </el-row>
    <div style="height: 30px;"></div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="投手" prop="uid">
        <el-select v-model="queryParams.uid" placeholder="请选择项目">
            <el-option
              v-for="dict in peoList"
              :key="dict.userId"
              :label="dict.nickName"
              :value="parseInt(dict.userId)"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="项目" prop="projectId">
        <el-select v-model="queryParams.projectId" placeholder="请选择项目">
            <el-option
              v-for="dict in proList"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="time">
        <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:packConsumeData:setPrice']"
        >新增</el-button>
      </el-col>
     
    </el-row>

    <el-table v-loading="loading" :data="packConsumeRecordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="投手" align="center" prop="userName" />
      <el-table-column label="已支付" align="center" prop="payAmount" />
      <el-table-column label="项目" align="center" prop="proName"/>
      <el-table-column label="日期" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进粉数" align="center" prop="num" />
      <el-table-column label="单价" align="center" prop="unit" />
      <el-table-column label="其他费用" align="center" prop="otherAmount" />
      <el-table-column label="其他费用说明" align="center" prop="remark" />
      <el-table-column label="售价" align="center" prop="price" />
      <el-table-column label="公司收益" align="center" prop="camExam" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:packConsumeRecords:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:packConsumeRecords:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改外包消耗记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="投手" prop="uid">
          <el-select v-model="form.uid" placeholder="请选择项目">
              <el-option
                v-for="dict in peoList"
                :key="dict.userId"
                :label="dict.nickName"
                :value="parseInt(dict.userId)"
              ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="项目" prop="projectId">
          <el-select v-model="form.projectId" placeholder="请选择项目">
            <el-option
              v-for="dict in proList"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日期" prop="time">
          <el-date-picker clearable
            v-model="form.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="售价" prop="price">
          <el-input v-model="form.price" placeholder="请输入售价" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPackConsumeRecords, getPackConsumeRecords, delPackConsumeRecords, addPackConsumeRecords, updatePackConsumeRecords,listPackConsumeRecordsAdmin,addPackConsumeDataSetPrice,allSummary } from "@/api/app/packConsumeRecords";
import { getProList } from "@/api/app/consumeRecords";
import { getPeoples } from "@/api/app/accountRecords";
import CountTo from 'vue-count-to'
export default {
  name: "PackConsumeRecords",
  dicts: ['tc_type'],
  components: {
    CountTo
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 外包消耗记录表格数据
      packConsumeRecordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uid: null,
        payAmount: null,
        projectId: null,
        time: null,
        num: null,
        unit: null,
        otherAmount: null,
        price: null,
        camExam: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        payAmount: [
          { required: true, message: "已支付不能为空", trigger: "blur" }
        ],
        projectId: [
          { required: true, message: "项目不能为空", trigger: "change" }
        ],
        time: [
          { required: true, message: "日期不能为空", trigger: "blur" }
        ],
        num: [
          { required: true, message: "进粉数不能为空", trigger: "blur" }
        ],
        unit: [
          { required: true, message: "单价不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "售价不能为空", trigger: "blur" }
        ],
        otherAmount: [
          { required: true, message: "其他费用不能为空", trigger: "blur" }
        ],
      },proList:[],dateRange:[],peoList:[],sumItem:{}
    };
  },
  mounted(){
    this.getList();
    this.getPros();
    this.getPeo();
    this.getAllTJ();
  },
  methods: {
           //个人统计
    getAllTJ(){
      allSummary(this.addDateRange(this.queryParams, this.dateRange)).then(res=>{
        this.sumItem = res.data
      })
    },
    //查询投手
    getPeo(){
      getPeoples().then(res=>{
        this.peoList = res.data;
      })
    },
    //项目列表
    getPros(){
      getProList().then(res=>{
        this.proList = res.data;
      })
    },
    /** 查询外包消耗记录列表 */
    getList() {
      this.loading = true;
      listPackConsumeRecordsAdmin(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.packConsumeRecordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        uid: null,
        payAmount: null,
        projectId: null,
        time: null,
        num: null,
        unit: null,
        otherAmount: null,
        remark: null,
        price: null,
        camExam: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.getAllTJ();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "设置售价";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPackConsumeRecords(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改外包消耗记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          addPackConsumeDataSetPrice(this.form).then(res=>{
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          })
          // if (this.form.id != null) {
          //   updatePackConsumeRecords(this.form).then(response => {
          //     this.$modal.msgSuccess("修改成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // } else {
          //   addPackConsumeRecords(this.form).then(response => {
        
          //   });
          // }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除外包消耗记录编号为"' + ids + '"的数据项？').then(function() {
        return delPackConsumeRecords(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/packConsumeRecords/export', {
        ...this.queryParams
      }, `packConsumeRecords_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
        color: #F56C6C;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;
    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
.tom-box{
  box-sizing: border-box;
  padding: 20px;
  box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
  height: 720px;
}
.table-box{
  box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
  box-sizing: border-box;
  padding: 20px;
  height: 720px;
}
</style>
